﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using System.Web.Security;
public partial class admin_Create_Site : System.Web.UI.Page {
    Decryption objdec = new Decryption();

    protected void Page_Load(object sender, EventArgs e) {

    }
    /// <summary>
    /// Handles the DataBound event of the FormViewSites control.
    /// Set the Client Name, if the page open from View_Client.aspx
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void FormViewSites_DataBound(object sender, EventArgs e) {
        DropDownList clientNameDDL = FormViewSites.FindControl("clientNameDropDownList") as DropDownList;
        PlaceHolder clientNamePH = FormViewSites.FindControl("clientNamePlaceHolder") as PlaceHolder;
        string client_id = "";
        try {
            client_id = objdec.DecodeUrl(Request.QueryString["client_id"].ToString());
        } catch (Exception err) {
            Console.Write("Err msg:" + err.Message);
        }
        if (client_id != "") {
            clientNamePH.Visible = false;
            clientNameLabel.Visible = true;
            clientNameDDL.SelectedIndex = clientNameDDL.Items.IndexOf(clientNameDDL.Items.FindByValue(client_id)); 
            clientNameLabel.Text = "for client: " + clientNameDDL.SelectedItem.Text;
        }
    }
    /// <summary>
    /// Handles the Click event of the InsertCancelButton control.
    /// Go to the source page
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void InsertCancelButton_Click(object sender, EventArgs e) {
        string client_id = "";
        try {
            client_id = objdec.DecodeUrl(Request.QueryString["client_id"].ToString());
        } catch (Exception err) {
            Console.Write("Err msg:" + err.Message);
        }
        if (client_id != "") {
            Server.Transfer("View_Client.aspx?client_id=" + client_id);
        } else {
            Server.Transfer("Mng_Site.aspx");
        }
    }
    /// <summary>
    /// Handles the ItemInserted event of the FormViewSites control.
    /// Go to the source page
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.FormViewInsertedEventArgs"/> instance containing the event data.</param>
    protected void FormViewSites_ItemInserted(object sender, FormViewInsertedEventArgs e) {
        string client_id = "";
        try {
            client_id = objdec.DecodeUrl(Request.QueryString["client_id"].ToString());
        } catch (Exception err) {
            Console.Write("Err msg:" + err.Message);
        }
        if (client_id != "") {
            Server.Transfer("View_Client.aspx?client_id=" + client_id);
        } else {
            Server.Transfer("Mng_Site.aspx");
        }
    }
    protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
    {


        Session.Contents.Remove("UserDetails");
        Session.Abandon();
        Session.Contents.RemoveAll();
        FormsAuthentication.SignOut();
        Response.Redirect("../Default.aspx");
    }
}
